/*
 * Copyright 1993-2013 NVIDIA Corporation.  All rights reserved.
 *
 * Please refer to the NVIDIA end user license agreement (EULA) associated
 * with this source code for terms and conditions that govern your use of
 * this software. Any use, reproduction, disclosure, or distribution of
 * this software and related documentation outside the terms of the EULA
 * is strictly prohibited.
 *
 */


// System includes
#include <stdio.h>
#include <assert.h>

// CUDA runtime
#include <cuda_runtime.h>

// helper functions and utilities to work with CUDA
#include <helper_functions.h>
#include <helper_cuda.h>

#include "cuPrintf.cu"

#ifndef MAX
#define MAX(a,b) (a > b ? a : b)
#endif

//The macro CUPRINTF is defined for architectures
//with different compute capabilities.
#if __CUDA_ARCH__ < 200     //Compute capability 1.x architectures
#define CUPRINTF cuPrintf
#else                       //Compute capability 2.x architectures
#define CUPRINTF(fmt, ...) printf("[%d, %d]:\t" fmt, \
                                  blockIdx.y*gridDim.x+blockIdx.x,\
                                  threadIdx.z*blockDim.x*blockDim.y+threadIdx.y*blockDim.x+threadIdx.x,\
                                  __VA_ARGS__)
#endif


__global__ void testKernel(int val)
{
    CUPRINTF("\tValue is:%d\n", val);
}

__global__ void device_greetings(void)
{
  cuPrintf("Hello, world from the device!\n");
}

int main(int argc, char **argv)
{
	 // greet from the host
	  printf("Hello, world from the host!\n");

	  // initialize cuPrintf
	  cudaPrintfInit();

	  // launch a kernel with a single thread to greet from the device
	  device_greetings<<<1,1>>>();

	  // display the device's greeting
	  cudaPrintfDisplay();

	  // clean up after cuPrintf
	  cudaPrintfEnd();

	  return 0;
}

